<?php
defined('ROOTPATH') OR exit('No direct script access allowed');
/**
 * HomeController
 */
use STONENYY\View as View;

class HomeController extends BaseController
{
    private $model;
    private $cache;

    public function __construct()
    {
        parent::__construct();
        $this->model = new TestModel;
        $this->cache = new Cache;
    }
    
    public function home()
    { 
        $id = isset($_GET['id'])?(int)$_GET['id']:1;

        if ($this->cache->exists('home_data_'.$id))
        {
            $data = $this->cache->read('home_data_'.$id);
        } else {
            $result = $this->model->getOne((int)$id);

            $data = $result;
            $this->cache->write('home_data_'.$id, $data);
        }
        
        // $this->core->viewLoad('home', $data);
        View::set(array('data' => $data));
        View::show('home');

        $this->model->close();
    }

    public function demo()
    {
        //
    }
}
